package com.rp.system.service;

import java.io.File;
import java.io.IOException;

import org.apache.commons.fileupload.FileItem;
import org.springframework.stereotype.Service;

import com.rp.common.utils.RpUtil;
import com.rp.goouploader.CustomOpera;
import com.rp.goouploader.GooFileInfo;
import com.rp.goouploader.GooForm;

@Service
public class UploadIconCustomOpera implements CustomOpera {

	@Override
	public void customOpera(GooFileInfo fileInfo, GooForm form, FileItem fileItem) {
		try {
			String fileName = fileInfo.getFileName();
			String className = form.getValue("className");
			String iconsCssWebServerDirPath = form.getValue("iconsCssWebServerDirPath");
			String content = "."+className+"{background:url(icons/"+fileName+") no-repeat;}";
			RpUtil.writeContent2File(iconsCssWebServerDirPath, content, true);
			
			//下面将上传的文件存入开发环境中
			String iconsSaveDevelopDir = form.getValue("iconsSaveDevelopDir");
			File file = new File(iconsSaveDevelopDir + "/" + fileName);
			fileItem.write(file);
			fileItem.delete();
			//下面将上传的图标信息写入开发环境的icons.css文件中
			String iconsCssSaveDevelopPath = form.getValue("iconsCssSaveDevelopPath");
			RpUtil.writeContent2File(iconsCssSaveDevelopPath, content, true);
			
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
